package com.spirng.leetcode.day08;

import java.util.*;

public class Test90 {
    public static void main(String[] args) {
        Test90 test90 = new Test90();
        test90.subsetsWithDup(new int[]{2,2,2});
    }
    ArrayList lists=new ArrayList<List<Integer>>();
    LinkedList list=new LinkedList<Integer>();
    public List<List<Integer>> subsetsWithDup(int[] nums) {
        Arrays.sort(nums);
        backtracking(nums,0,new int[nums.length]);
        return lists;
    }
    public void  backtracking(int [] nums,int startSize,int [] use){
        lists.add(new ArrayList<>(list));
        if(startSize>= nums.length){
            return;
        }
        for (int i = startSize; i < nums.length; i++) {
            if(i>0&&nums[i-1]==nums[i]&&use[i-1]==0){
                continue;
            }
            use[i]=1;
            list.add(nums[i]);
            backtracking(nums,i+1,use);
            list.removeLast();
            use[i]=0;
        }
    }
}
